/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entity.Iphonetype;
import java.util.ArrayList;
import org.hibernate.Query;
import org.hibernate.Session;
import util.AppHibernateUtil;

/**
 *
 * @author Turtle
 */
public class IphoneTypeDAO {
    
    public static Iphonetype getTypeByID(String id) {
        Iphonetype type = new Iphonetype();

        Session session = AppHibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();

        String hql = "from Iphonetype where id=:_id";

        Query query = session.createQuery(hql);
        query.setParameter("_id", id);

        ArrayList<Iphonetype> list = (ArrayList<Iphonetype>) query.list();

        if (list.size() > 0) {
            type = (Iphonetype) query.list().get(0);
        }

        return type;
    }
    
     public static ArrayList<Iphonetype> getTypeList() {
        ArrayList<Iphonetype> type = new ArrayList<Iphonetype>();

        Session session = AppHibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();

        String hql = "from Iphonetype";

        Query query = session.createQuery(hql);

        type = (ArrayList<Iphonetype>) query.list();

        return type;
    }
}
